<?php
namespace App\Services;
use Hanson\Face\Foundation\Face;
use Godruoyi\OCR\Application;

Class Idcard
{
	// 正面信息 颜值，姓名，生日等信息
    public static function getIdcardInfo_A($filePath)
	{
		$face = new Face();
        //dd($filePath);
    	$yanzhi = $face->score->get($filePath);



        $app = new Application([
            'ocrs' => [
                'baidu' => [
                    'app_key'    => 'XuP5aYWd5vsXxGrxvKvYSA40',
                    'secret_key' => 'pp97n7QkXHGbl2E7UluRTKuw1YhOmkjF'
                ],
            ]
        ]);

        //身份证识别
        $result = $app->baidu->idcard($filePath,[
                        'detect_direction'      => false,      //是否检测图像朝向
                        'id_card_side'          => 'front',    //front：身份证正面；back：身份证背面 （注意，该参数必选）
                        'detect_risk'           => false,      //是否开启身份证风险类型功能，默认false
                    ]);
        $idInfo = $result['words_result'];
        $address = array_get($idInfo,'住址.words');
        $data['huji']     = huji($address);
        $data['truename']   = array_get($idInfo,'姓名.words');
        $data['idcard']     = array_get($idInfo,'公民身份号码.words');
        $data['birthday']   = array_get($idInfo,'出生.words');
        $data['sex']        = array_get($idInfo,'性别.words');
        $data['face_score'] = array_get($yanzhi,'score');

        if($data['birthday']) {
            $rz_year  = substr($data['birthday'],0,4);
            $rz_month = substr($data['birthday'],4,2);
            $rz_day   = substr($data['birthday'],6,2);            
            $sizhu = new Sizhu();
            $data['rizhu'] = $sizhu->rizhu($rz_year,$rz_month,$rz_day);   
        }
       
        return $data;	
	}

    // 正面信息 颜值，姓名，生日等信息
    public static function getIdcardInfo_B($filePath)
    {
        $app = new Application([
            'ocrs' => [
                'baidu' => [
                    'app_key'    => 'XuP5aYWd5vsXxGrxvKvYSA40',
                    'secret_key' => 'pp97n7QkXHGbl2E7UluRTKuw1YhOmkjF'
                ],
            ]
        ]);

        //身份证识别
        $result = $app->baidu->idcard($filePath,[
                        'detect_direction'      => false,      //是否检测图像朝向
                        'id_card_side'          => 'back',    //front：身份证正面；back：身份证背面 （注意，该参数必选）
                        'detect_risk'           => false,      //是否开启身份证风险类型功能，默认false
                    ]);
        $idInfo = $result['words_result'];
        $begin = array_get($idInfo,'签发日期.words');
        $end   = array_get($idInfo,'失效日期.words');
        $data['idcard_validate']   = $begin.'-'.$end;
        $data['idcard_jiguan']     = array_get($idInfo,'签发机关.words');
       
        //dd($idInfo);
        
        return $data;   
    }
	
}